
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_Hans">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>django.urls 实用函数 &#8212; Django 3.2.6.dev 文档</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="next" title="URLconfs 中使用的 django.urls 函数" href="urls.html" />
    <link rel="prev" title="Unicode 数据" href="unicode.html" />



 
<script src="../templatebuiltins.js"></script>
<script>
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);</script>

  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../index.html">Django 3.2.6.dev 文档</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../index.html">Home</a>  |
        <a title="Table of contents" href="../contents.html">Table of contents</a>  |
        <a title="Global index" href="../genindex.html">Index</a>  |
        <a title="Module index" href="../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="unicode.html" title="Unicode 数据">previous</a>
     |
    <a href="index.html" title="API 参考" accesskey="U">up</a>
   |
    <a href="urls.html" title="URLconfs 中使用的 &lt;code class=&#34;docutils literal notranslate&#34;&gt;&lt;span class=&#34;pre&#34;&gt;django.urls&lt;/span&gt;&lt;/code&gt; 函数">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="ref-urlresolvers">
            
  <div class="section" id="s-module-django.urls">
<span id="s-django-urls-utility-functions"></span><span id="module-django.urls"></span><span id="django-urls-utility-functions"></span><h1><code class="docutils literal notranslate"><span class="pre">django.urls</span></code> 实用函数<a class="headerlink" href="#module-django.urls" title="永久链接至标题">¶</a></h1>
<div class="section" id="s-reverse">
<span id="reverse"></span><h2>reverse()<a class="headerlink" href="#reverse" title="永久链接至标题">¶</a></h2>
<p>如果你需要在你的代码中使用类似于 <a class="reference internal" href="templates/builtins.html#std:templatetag-url"><code class="xref std std-ttag docutils literal notranslate"><span class="pre">url</span></code></a> 模板标签的东西，Django 提供了以下函数：</p>
<dl class="function">
<dt id="django.urls.reverse">
<code class="descname">reverse</code>(<em>viewname</em>, <em>urlconf=None</em>, <em>args=None</em>, <em>kwargs=None</em>, <em>current_app=None</em>)<a class="headerlink" href="#django.urls.reverse" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p><code class="docutils literal notranslate"><span class="pre">viewname</span></code> 可以是一个 <a class="reference internal" href="../topics/http/urls.html#naming-url-patterns"><span class="std std-ref">URL 模式名称</span></a> 或者是可调用的视图对象。例如，给定以下 <code class="docutils literal notranslate"><span class="pre">url</span></code>：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">news</span> <span class="kn">import</span> <span class="n">views</span>

<span class="n">path</span><span class="p">(</span><span class="s1">&#39;archive/&#39;</span><span class="p">,</span> <span class="n">views</span><span class="o">.</span><span class="n">archive</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;news-archive&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>你可以使用以下任何一种方式来反查 URL：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># using the named URL</span>
<span class="n">reverse</span><span class="p">(</span><span class="s1">&#39;news-archive&#39;</span><span class="p">)</span>

<span class="c1"># passing a callable object</span>
<span class="c1"># (This is discouraged because you can&#39;t reverse namespaced views this way.)</span>
<span class="kn">from</span> <span class="nn">news</span> <span class="kn">import</span> <span class="n">views</span>
<span class="n">reverse</span><span class="p">(</span><span class="n">views</span><span class="o">.</span><span class="n">archive</span><span class="p">)</span>
</pre></div>
</div>
<p>如果 URL 接受参数，你可以在 <code class="docutils literal notranslate"><span class="pre">args</span></code> 中传递参数。例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.urls</span> <span class="kn">import</span> <span class="n">reverse</span>

<span class="k">def</span> <span class="nf">myview</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">HttpResponseRedirect</span><span class="p">(</span><span class="n">reverse</span><span class="p">(</span><span class="s1">&#39;arch-summary&#39;</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="mi">1945</span><span class="p">]))</span>
</pre></div>
</div>
<p>你也可以通过 <code class="docutils literal notranslate"><span class="pre">kwargs</span></code> 代替 <code class="docutils literal notranslate"><span class="pre">args</span></code>。例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">reverse</span><span class="p">(</span><span class="s1">&#39;admin:app_list&#39;</span><span class="p">,</span> <span class="n">kwargs</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;app_label&#39;</span><span class="p">:</span> <span class="s1">&#39;auth&#39;</span><span class="p">})</span>
<span class="go">&#39;/admin/auth/&#39;</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">args</span></code> 和 <code class="docutils literal notranslate"><span class="pre">kwargs</span></code> 不能同时传递给 <code class="docutils literal notranslate"><span class="pre">reverse()</span></code>。</p>
<p>如果不能匹配，<code class="docutils literal notranslate"><span class="pre">reverse()</span></code> 会引发一个 <a class="reference internal" href="exceptions.html#django.urls.NoReverseMatch" title="django.urls.NoReverseMatch"><code class="xref py py-class docutils literal notranslate"><span class="pre">NoReverseMatch</span></code></a> 异常。</p>
<p><code class="docutils literal notranslate"><span class="pre">reverse()</span></code> 函数可以反查 URL 的多种正则表达式模式，但不是每一种可能的模式。目前主要的限制是，模式不能包含使用竖条（<code class="docutils literal notranslate"><span class="pre">&quot;|&quot;</span></code>）字符的替代选择。你可以很高兴地使用这样的模式与传入的 URL 进行匹配，并将它们发送给视图，但你不能反查这样的模式。</p>
<p><code class="docutils literal notranslate"><span class="pre">current_app</span></code> 参数允许你向解析器提供一个提示，说明当前执行的视图属于哪个应用程序。这个 <code class="docutils literal notranslate"><span class="pre">current_app</span></code> 参数被用作提示，以便根据 <a class="reference internal" href="../topics/http/urls.html#topics-http-reversing-url-namespaces"><span class="std std-ref">命名空间的 URL 解析策略</span></a>，将应用程序名称空间解析为特定应用程序实例上的 URL。</p>
<p><code class="docutils literal notranslate"><span class="pre">urlconf</span></code> 参数是 URLconf 模块，其中包含用于反查的 URL 模式。默认情况下，使用的是当前线程的根 URLconf。</p>
<div class="admonition note">
<p class="first admonition-title">注解</p>
<p><code class="docutils literal notranslate"><span class="pre">reverse()</span></code> 返回的字符串已经是 <a class="reference internal" href="unicode.html#uri-and-iri-handling"><span class="std std-ref">url 转义的</span></a>。例如：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">reverse</span><span class="p">(</span><span class="s1">&#39;cities&#39;</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;Orléans&#39;</span><span class="p">])</span>
<span class="go">&#39;.../Orl%C3%A9ans/&#39;</span>
</pre></div>
</div>
<p class="last">对 <code class="docutils literal notranslate"><span class="pre">reverse()</span></code> 的输出应用进一步的编码（如 <a class="reference external" href="https://docs.python.org/3/library/urllib.parse.html#urllib.parse.quote" title="(在 Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib.parse.quote()</span></code></a>）可能会产生不理想的结果。</p>
</div>
</div>
<div class="section" id="s-reverse-lazy">
<span id="reverse-lazy"></span><h2><code class="docutils literal notranslate"><span class="pre">reverse_lazy()</span></code><a class="headerlink" href="#reverse-lazy" title="永久链接至标题">¶</a></h2>
<p><a class="reference internal" href="#reverse">reverse()</a> 的惰性执行版本。</p>
<dl class="function">
<dt id="django.urls.reverse_lazy">
<code class="descname">reverse_lazy</code>(<em>viewname</em>, <em>urlconf=None</em>, <em>args=None</em>, <em>kwargs=None</em>, <em>current_app=None</em>)<a class="headerlink" href="#django.urls.reverse_lazy" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>当你需要在你的项目的 URLConf 被加载之前使用 URL 反查时，这个功能很有用。一些常见的需要使用该功能的情况是：</p>
<ul class="simple">
<li>提供一个反查的 URL 作为基于类的通用视图的 <code class="docutils literal notranslate"><span class="pre">url</span></code> 属性。</li>
<li>为装饰器提供一个反查的 URL（例如 <a class="reference internal" href="../topics/auth/default.html#django.contrib.auth.decorators.permission_required" title="django.contrib.auth.decorators.permission_required"><code class="xref py py-func docutils literal notranslate"><span class="pre">django.contrib.auth.decorators.permission_required()</span></code></a> 装饰器的 <code class="docutils literal notranslate"><span class="pre">login_url</span></code> 参数）。</li>
<li>提供一个反查的 URL 作为函数签名中参数的默认值。</li>
</ul>
</div>
<div class="section" id="s-resolve">
<span id="resolve"></span><h2><code class="docutils literal notranslate"><span class="pre">resolve()</span></code><a class="headerlink" href="#resolve" title="永久链接至标题">¶</a></h2>
<p><code class="docutils literal notranslate"><span class="pre">resolve()</span></code> 函数可用于解析到相应视图函数的 URL 路径。该函数的签名如下：</p>
<dl class="function">
<dt id="django.urls.resolve">
<code class="descname">resolve</code>(<em>path</em>, <em>urlconf=None</em>)<a class="headerlink" href="#django.urls.resolve" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p><code class="docutils literal notranslate"><span class="pre">path</span></code> 是你要解析的 URL 路径。与 <a class="reference internal" href="#django.urls.reverse" title="django.urls.reverse"><code class="xref py py-func docutils literal notranslate"><span class="pre">reverse()</span></code></a> 一样，你不需要担心 <code class="docutils literal notranslate"><span class="pre">urlconf</span></code> 参数。该函数返回一个 <a class="reference internal" href="#django.urls.ResolverMatch" title="django.urls.ResolverMatch"><code class="xref py py-class docutils literal notranslate"><span class="pre">ResolverMatch</span></code></a> 对象，允许你访问关于解析 URL 的各种元数据。</p>
<p>如果 URL 没有解析，函数会引发一个 <a class="reference internal" href="exceptions.html#django.urls.Resolver404" title="django.urls.Resolver404"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Resolver404</span></code></a> 异常（<a class="reference internal" href="../topics/http/views.html#django.http.Http404" title="django.http.Http404"><code class="xref py py-class docutils literal notranslate"><span class="pre">Http404</span></code></a> 的一个子类）。</p>
<dl class="class">
<dt id="django.urls.ResolverMatch">
<em class="property">class </em><code class="descname">ResolverMatch</code><a class="headerlink" href="#django.urls.ResolverMatch" title="永久链接至目标">¶</a></dt>
<dd><dl class="attribute">
<dt id="django.urls.ResolverMatch.func">
<code class="descname">func</code><a class="headerlink" href="#django.urls.ResolverMatch.func" title="永久链接至目标">¶</a></dt>
<dd><p>用于服务 URL 的视图函数。</p>
</dd></dl>

<dl class="attribute">
<dt id="django.urls.ResolverMatch.args">
<code class="descname">args</code><a class="headerlink" href="#django.urls.ResolverMatch.args" title="永久链接至目标">¶</a></dt>
<dd><p>从 URL 中解析出的传递给视图函数的参数。</p>
</dd></dl>

<dl class="attribute">
<dt id="django.urls.ResolverMatch.kwargs">
<code class="descname">kwargs</code><a class="headerlink" href="#django.urls.ResolverMatch.kwargs" title="永久链接至目标">¶</a></dt>
<dd><p>从 URL 中解析出的可能传递给视图函数的关键字参数。</p>
</dd></dl>

<dl class="attribute">
<dt id="django.urls.ResolverMatch.url_name">
<code class="descname">url_name</code><a class="headerlink" href="#django.urls.ResolverMatch.url_name" title="永久链接至目标">¶</a></dt>
<dd><p>与 URL 匹配的 URL 模式的名称。</p>
</dd></dl>

<dl class="attribute">
<dt id="django.urls.ResolverMatch.route">
<code class="descname">route</code><a class="headerlink" href="#django.urls.ResolverMatch.route" title="永久链接至目标">¶</a></dt>
<dd><p>匹配 URL 模式的路径。</p>
<p>例如，如果 <code class="docutils literal notranslate"><span class="pre">path('users/&lt;id&gt;/',</span> <span class="pre">...)``是匹配的模式，``route</span></code> 将包含 <code class="docutils literal notranslate"><span class="pre">'users/&lt;id&gt;/'</span></code>。</p>
</dd></dl>

<dl class="attribute">
<dt id="django.urls.ResolverMatch.tried">
<code class="descname">tried</code><a class="headerlink" href="#django.urls.ResolverMatch.tried" title="永久链接至目标">¶</a></dt>
<dd><div class="versionadded">
<span class="title">New in Django 3.2.</span> </div>
<p>The list of URL patterns tried before the URL either matched one or
exhausted available patterns.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.urls.ResolverMatch.app_name">
<code class="descname">app_name</code><a class="headerlink" href="#django.urls.ResolverMatch.app_name" title="永久链接至目标">¶</a></dt>
<dd><p>匹配 URL 模式的应用程序命名空间。</p>
</dd></dl>

<dl class="attribute">
<dt id="django.urls.ResolverMatch.app_names">
<code class="descname">app_names</code><a class="headerlink" href="#django.urls.ResolverMatch.app_names" title="永久链接至目标">¶</a></dt>
<dd><p>匹配 URL 模式的完整应用程序命名空间中的单个命名空间组件列表。例如，如果 <code class="docutils literal notranslate"><span class="pre">app_name</span></code> 是 <code class="docutils literal notranslate"><span class="pre">'foo:bar'</span></code>，那么 <code class="docutils literal notranslate"><span class="pre">app_names</span></code> 将是 <code class="docutils literal notranslate"><span class="pre">['foo',</span> <span class="pre">'bar']</span></code>。</p>
</dd></dl>

<dl class="attribute">
<dt id="django.urls.ResolverMatch.namespace">
<code class="descname">namespace</code><a class="headerlink" href="#django.urls.ResolverMatch.namespace" title="永久链接至目标">¶</a></dt>
<dd><p>匹配 URL 模式的实例命名空间。</p>
</dd></dl>

<dl class="attribute">
<dt id="django.urls.ResolverMatch.namespaces">
<code class="descname">namespaces</code><a class="headerlink" href="#django.urls.ResolverMatch.namespaces" title="永久链接至目标">¶</a></dt>
<dd><p>匹配 URL 模式的完整实例命名空间中的单个命名空间组件列表，即，如果命名空间是 <code class="docutils literal notranslate"><span class="pre">foo:bar</span></code>，那么命名空间将是 <code class="docutils literal notranslate"><span class="pre">['foo'，'bar']</span></code>。</p>
</dd></dl>

<dl class="attribute">
<dt id="django.urls.ResolverMatch.view_name">
<code class="descname">view_name</code><a class="headerlink" href="#django.urls.ResolverMatch.view_name" title="永久链接至目标">¶</a></dt>
<dd><p>匹配 URL 的视图名称，包括命名空间（如果有的话）。</p>
</dd></dl>

</dd></dl>

<p>然后可以查询一个 <a class="reference internal" href="#django.urls.ResolverMatch" title="django.urls.ResolverMatch"><code class="xref py py-class docutils literal notranslate"><span class="pre">ResolverMatch</span></code></a> 对象，以提供与 URL 相匹配的 URL 模式的信息：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Resolve a URL</span>
<span class="n">match</span> <span class="o">=</span> <span class="n">resolve</span><span class="p">(</span><span class="s1">&#39;/some/path/&#39;</span><span class="p">)</span>
<span class="c1"># Print the URL pattern that matches the URL</span>
<span class="nb">print</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">url_name</span><span class="p">)</span>
</pre></div>
</div>
<p>一个 <a class="reference internal" href="#django.urls.ResolverMatch" title="django.urls.ResolverMatch"><code class="xref py py-class docutils literal notranslate"><span class="pre">ResolverMatch</span></code></a> 对象也可以解包为以下三个：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">func</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">kwargs</span> <span class="o">=</span> <span class="n">resolve</span><span class="p">(</span><span class="s1">&#39;/some/path/&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p><a class="reference internal" href="#django.urls.resolve" title="django.urls.resolve"><code class="xref py py-func docutils literal notranslate"><span class="pre">resolve()</span></code></a> 的一个可能的用法是测试一个视图在重定向到它之前是否会引发 <code class="docutils literal notranslate"><span class="pre">Http404</span></code> 错误：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">urllib.parse</span> <span class="kn">import</span> <span class="n">urlparse</span>
<span class="kn">from</span> <span class="nn">django.urls</span> <span class="kn">import</span> <span class="n">resolve</span>
<span class="kn">from</span> <span class="nn">django.http</span> <span class="kn">import</span> <span class="n">Http404</span><span class="p">,</span> <span class="n">HttpResponseRedirect</span>

<span class="k">def</span> <span class="nf">myview</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="nb">next</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">META</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;HTTP_REFERER&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="ow">or</span> <span class="s1">&#39;/&#39;</span>
    <span class="n">response</span> <span class="o">=</span> <span class="n">HttpResponseRedirect</span><span class="p">(</span><span class="nb">next</span><span class="p">)</span>

    <span class="c1"># modify the request and response as required, e.g. change locale</span>
    <span class="c1"># and set corresponding locale cookie</span>

    <span class="n">view</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">kwargs</span> <span class="o">=</span> <span class="n">resolve</span><span class="p">(</span><span class="n">urlparse</span><span class="p">(</span><span class="nb">next</span><span class="p">)[</span><span class="mi">2</span><span class="p">])</span>
    <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;request&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">request</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">view</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    <span class="k">except</span> <span class="n">Http404</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">HttpResponseRedirect</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">response</span>
</pre></div>
</div>
</div>
<div class="section" id="s-get-script-prefix">
<span id="get-script-prefix"></span><h2><code class="docutils literal notranslate"><span class="pre">get_script_prefix()</span></code><a class="headerlink" href="#get-script-prefix" title="永久链接至标题">¶</a></h2>
<dl class="function">
<dt id="django.urls.get_script_prefix">
<code class="descname">get_script_prefix</code>()<a class="headerlink" href="#django.urls.get_script_prefix" title="永久链接至目标">¶</a></dt>
<dd></dd></dl>

<p>通常情况下，你应该总是使用 <a class="reference internal" href="#django.urls.reverse" title="django.urls.reverse"><code class="xref py py-func docutils literal notranslate"><span class="pre">reverse()</span></code></a> 来定义应用程序中的 URL。然而，如果你的应用程序自己构造了部分 URL 层次结构，你可能偶尔需要生成 URL。在这种情况下，你需要能够在 Web 服务器中找到 Django 项目的基本 URL（通常，<a class="reference internal" href="#django.urls.reverse" title="django.urls.reverse"><code class="xref py py-func docutils literal notranslate"><span class="pre">reverse()</span></code></a> 会帮你处理这个问题）。在这种情况下，你可以调用 <code class="docutils literal notranslate"><span class="pre">get_script_prefix()</span></code>，它将返回 Django 项目的 URL 的脚本前缀部分。如果你的 Django 项目是在 web 服务器的根目录下，那么它总是 <code class="docutils literal notranslate"><span class="pre">&quot;/&quot;</span></code>。</p>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#"><code class="docutils literal notranslate"><span class="pre">django.urls</span></code> 实用函数</a><ul>
<li><a class="reference internal" href="#reverse">reverse()</a></li>
<li><a class="reference internal" href="#reverse-lazy"><code class="docutils literal notranslate"><span class="pre">reverse_lazy()</span></code></a></li>
<li><a class="reference internal" href="#resolve"><code class="docutils literal notranslate"><span class="pre">resolve()</span></code></a></li>
<li><a class="reference internal" href="#get-script-prefix"><code class="docutils literal notranslate"><span class="pre">get_script_prefix()</span></code></a></li>
</ul>
</li>
</ul>

  <h4>上一个主题</h4>
  <p class="topless"><a href="unicode.html"
                        title="上一章">Unicode 数据</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="urls.html"
                        title="下一章">URLconfs 中使用的 <code class="docutils literal notranslate"><span class="pre">django.urls</span></code> 函数</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/ref/urlresolvers.txt"
            rel="nofollow">显示源代码</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>快速搜索</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="转向" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">7月 23, 2021</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="unicode.html" title="Unicode 数据">previous</a>
     |
    <a href="index.html" title="API 参考" accesskey="U">up</a>
   |
    <a href="urls.html" title="URLconfs 中使用的 &lt;code class=&#34;docutils literal notranslate&#34;&gt;&lt;span class=&#34;pre&#34;&gt;django.urls&lt;/span&gt;&lt;/code&gt; 函数">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>